<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-link to="/home/123">主页1</router-link>
        <router-link to="/home/234">主页2</router-link>
        <router-link to="/commpany">企业介绍</router-link>
        <router-view></router-view>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vue-router/dist/vue-router.js"></script>
<script>
    let Commpany = {
        template:`<h1>公司内容</h1>`
    }
    let routes = [
        {
            path:"/home/:id",
            beforeEnter:(to,from,next)=>{
                console.log("/home 路由导航守卫");
                next();
            },
            component:()=>Promise.resolve({
                template:`<h1>主页内容</h1>`,
                beforeRouteEnter:(to,from,next)=>{
                    console.log("组件守卫导航 进入主页的路由");
                    next();
                },
                beforeRouteUpdate:(to,from,next)=>{
                    console.log("组件守卫导航 主页 路由更新的时候");
                    next();
                },
                beforeRouteLeave:(to,from,next)=>{
                    console.log("组件守卫导航 离开主页路由的时候");
                    next();
                },
            })
        },
        {
            path:"/commpany",
            component:Commpany
        },
    ];
    let router = new VueRouter({
        routes
    })
    router.beforeEach((to,from,next)=>{
        console.log("全局配置的导航守卫");
        next();
    })
    let vm = new Vue({
        router,
        el:"#app"
    });
</script>
</html>